<?php

/*
	info: 用户登录
*/

require '../common.inc.php';

global_CheckPost(
	array(
		array('email','email','',$weblang['api_userEmailError'],1),
		array('password','str','',$weblang['api_userPasswordError'],1),
));

if (!empty($webglobal['CPM']))
{
	$objmem->ClearUserCookie();
	$return['code'] = 1;
	$return['msg'] = reset($webglobal['CPM']);
	api_EchoReturn();
}

$webglobal['datainfo'] = $db->GetOne("SELECT * FROM user WHERE email='{$webglobal['CPP']['email']}'");
if (empty($webglobal['datainfo']))
{
	$objmem->ClearUserCookie();
	$return['code'] = 1;
	$return['msg'] = $weblang['api_userEmailError'];
	api_EchoReturn();
}

$user['m_islogin'] = $objmem->CheckUser($webglobal['CPP']['email'], $webglobal['CPP']['password']);
if (!$user['m_islogin'])
{
	$objmem->ClearUserCookie();
	$return['code'] = 4;
	$return['msg'] = $weblang['api_userPasswordError'];
	api_EchoReturn();
}


$objmem->SetUserCookie($webglobal['datainfo']['email'], $webglobal['datainfo']['password'], $webglobal['loginintime']);

$return['code'] = 0;
$return['data']['member'] = array(
	'uid' => $webglobal['datainfo']['uid'],
	'truename' => $webglobal['datainfo']['truename'],
	'email' => $webglobal['datainfo']['email'],
	'mobile' => $webglobal['datainfo']['mobile'],
	'weddingdate' => global_FormatTime($webglobal['datainfo']['weddingdate'], $webglobal['weddingdatemode']),
);

$return['data']['ischeckcode'] = false;
$return['data']['isReserved'] = false;
$webglobal['CPP']['id'] = api_GetTopActivityID();
$webglobal['codeinfo'] = $db->GetOne("SELECT U.sid,U.peoplenum,U.codetime,S.* FROM promotion_user U LEFT JOIN promotion_site S ON (U.sid=S.id) WHERE U.uid='{$user['m_uid']}' AND U.pid='{$webglobal['CPP']['id']}'");
if (!empty($webglobal['codeinfo']))
{
	$return['data']['ischeckcode'] = true;
	if ($webglobal['codeinfo']['peoplenum']>0 && !empty($webglobal['codeinfo']['id']))
	{
		$return['data']['isReserved'] = true;
	}
}

api_EchoReturn();
